<?php
namespace App\Model;
use Core\Component\Di;

class ChatRecord{
    protected $db;
    protected $tableName = 'chat_record';

    function __construct(){
        $db = Di::getInstance()->get("MYSQL");
        if($db instanceof \MysqliDb){
            $this->db = $db;
        }
    }

    public function addChatRecord($userId){
        if(!$userId){
            return [];
        }
        $this->db->where("user_id", $userId);
        $this->db->where("status", 1);
        $column = 'friend_id as friendId';
        $info = $this->db->get($this->tableName,NULL,$column);
        if(!$info){
            return [];
        }
        return array_column($info, 'friendId');
    }

    public function getChatRecord($userId){
        if(!$userId){
            return [];
        }
        $this->db->where("user_id", $userId);
        $this->db->where("status", 1);
        $column = 'friend_id as friendId';
        $info = $this->db->get($this->tableName,NULL,$column);
        if(!$info){
            return [];
        }
        return array_column($info, 'friendId');
    }
}
